package ajaxtest;

import java.sql.ResultSet;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ModelDriven;

public class adminAction implements ModelDriven{
	admin admin = null;
	public String login() {
		DBManager dbManager = new DBManager();
		String sql= "select * from admin where username = '"+admin.getUsername()+"' and password = '"+admin.getPassword()+"'";
		ResultSet resultSet = dbManager.executeQuery(sql);
		try {
			if (resultSet.next()) {
			System.out.println("登陆成功");
			ActionContext.getContext().getSession().put("admin", admin);
			return "success";
		}else {
			ActionContext.getContext().getSession().put("message", "登录失败");
			return "failed";
		}
		} catch (Exception e) {
			e.printStackTrace();
			ActionContext.getContext().getSession().put("message", "登录失败");
			// TODO: handle exception
		}finally{
			dbManager.closeConnection();
		}
		
		return "failed";
	}

	@Override
	public Object getModel() {
		// TODO Auto-generated method stub
		if (admin == null) {
			admin = new admin();
		}
		return admin;
	}
}
